home *** CD-ROM | disk | FTP | other *** search
Text File | 1996-05-21 | 9.6 KB | 409 lines | [TEXT/ttxt] |
- in module HolidayModule
-
- -- if stationary IV is set, the objects behind it will not be draw
- -- thus a white box appears
-
- class Background (GroupPresenter)
- inst vars
- bg
- kman
- status : @stop
- end
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: Background
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class Background} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap
- return theBMP
- )
-
- method setupBG self {class Background} ->
- (
- local bgBitmap := (importBitmap self mediaDir "bkground.bmp")
- local background := new TwoDShape boundary:bgBitmap fill:defaultBrush
- background.position := new Point x:0 y:0
- background.stationary := true
- self.bg := background
- )
-
- method setupKman self {class Background} ->
- (
- local kmanBitmap := (importBitmap self mediaDir "kman.bmp")
- local kman := new TwoDShape boundary:kmanBitmap fill:defaultBrush
- kman.position := new Point x:185 y:550
- kman.stationary := true
- self.kman := kman
- )
-
- method addBG self {class Background} ->
- (
- append self self.bg
- )
-
- method addKman self {class Background} ->
- (
- append self self.kman
- )
-
- method removeBG self {class Background} ->
- (
- deleteOne self self.bg
- )
-
- method removeKman self {class Background} ->
- (
- deleteOne self self.kman
- )
-
- method play self {class Background} ->
- (
- self.status := @play
- )
-
- method stop self {class Background} ->
- (
- self.status := @stop
- )
-
- method startScroll self {class Background} ->
- (
- addKman self
- play self
- )
-
- method stopScroll self {class Background} ->
- (
- stop self
- removeBG self
- )
-
- method tick self {class Background} clk ->
- (
- if self.status != @stop do
- self.y := self.y - 3
- )
-
- method afterInit self {class Background} #rest args ->
- (
- setupBG self
- setupKman self
-
- self
- )
-
-
- class FlyBy (GroupPresenter)
- inst vars
- status
- tiny
- banner
- sleigh
- penguins : #()
- end
-
- --*=============================================================================*
- --* Method name: importBitmap
- --* Class: FlyBy
- --* Usage: importBitmap self mediaDir bitmapFile
- --* mediaDir - DirRep
- --* bitmapFile - String object
- --*-----------------------------------------------------------------------------*
- --* Description: Imports the given bitmap from the given directory.
- --*=============================================================================*
- method importBitmap self {class FlyBy} mediaDir bitmapFile ->
- (
- local theStream := getStream mediaDir bitmapFile @readable
- local theBMP := importMedia theImportExportEngine theStream @image @dib @bitmap
- theBMP.invisibleColor := (new RGBColor red:51 green:51 blue:255)
- return theBMP
- )
-
- --*=============================================================================*
- --* Method name: importSeries
- --* Class: FlyBy
- --* Usage: importSeries self mediaDir
- --* mediaDir - DirRep
- --*-----------------------------------------------------------------------------*
- --* Description: Imports all bitmaps in the given directory.
- --*=============================================================================*
- method importSeries self {class FlyBy} mediaDir ->
- (
- local series := #()
-
- --*=========================================================================*
- --* Import all files in the 'media' folder
- --*=========================================================================*
- for bitmapFile in (getContents mediaDir) do
- append series (importBitmap self mediaDir bitmapFile)
-
- --*=========================================================================*
- --* Complete the animation loop
- --*=========================================================================*
- for i := ((size series) - 1) to 2 by -1 do
- append series series[i]
-
- return series
- )
-
- method makePenguin self {class FlyBy} series position scale ->
- (
- local thePenguin := new Animation series:series scale:scale
- thePenguin.isTransparent := true
- thePenguin.position := position
- append self.penguins thePenguin
- )
-
- method setupPenguins self {class FlyBy} ->
- (
- -- make penguin 1
- local pen1Dir := spawn mediaDir "pen1"
- local penguinList := (importSeries self pen1Dir)
- makePenguin self penguinList (new Point x:1075 y:87) 5
-
- -- make penguin 2
- local pen2Dir := spawn mediaDir "pen2"
- local penguinList := (importSeries self pen2Dir)
- makePenguin self penguinList (new Point x:1002 y:90) 6
-
- -- make penguin 3
- local pen3Dir := spawn mediaDir "pen3"
- local penguinList := (importSeries self pen3Dir)
- makePenguin self penguinList (new Point x:923 y:71) 8
-
- -- make penguin 4
- local pen4Dir := spawn mediaDir "pen4"
- local penguinList := (importSeries self pen4Dir)
- makePenguin self penguinList (new Point x:849 y:80) 4
-
- self
- )
-
- method setupSleigh self {class FlyBy} ->
- (
- local sleighBitmap := (importBitmap self mediaDir "sleigh.bmp")
- local sleigh := new TwoDShape boundary:sleighBitmap fill:defaultBrush
- sleigh.position := new Point x:7 y:10
- sleigh.stationary := true
- sleigh.isTransparent := true
- self.sleigh := sleigh
- )
-
- method setupTiny self {class Flyby} ->
- (
- local tinyBitmap := (importBitmap self mediaDir "tiny.bmp")
- local tiny := new TwoDShape boundary:tinyBitmap fill:defaultBrush
- tiny.stationary := true
- tiny.isTransparent := true
- self.tiny := tiny
- )
-
- method addPenguins self {class FlyBy} ->
- (
- foreach self.penguins (penguin -> start penguin; append self penguin) undefined
- -- print "add penguins"
- )
-
- method addSleigh self {class FlyBy} ->
- (
- append self self.sleigh
- -- print "add sleigh"
- )
-
- method addTiny self {class FlyBy} ->
- (
- append self self.tiny
- self.y := 25
- playLeft self
- -- print "add tiny"
- )
-
- method removePenguins self {class FlyBy} ->
- (
- foreach self.penguins (penguin -> stop penguin; deleteOne self penguin) undefined
- -- print "remove penguins"
- )
-
- method removeSleigh self {class FlyBy} ->
- (
- deleteOne self self.sleigh
- -- print "remove sleigh"
- )
-
- method removeTiny self {class FlyBy} ->
- (
- deleteOne self self.tiny
- -- print "remove tiny"
- )
-
- method playRight self {class FlyBy} ->
- (
- self.status := @playright
- )
-
- method playLeft self {class FlyBy} ->
- (
- self.status := @playleft
- )
-
- method stop self {class FlyBy} ->
- (
- self.status := @stop
- )
-
- method tick self {class FlyBy} clk ->
- (
- if self.status = @stop do
- return
-
- if (self.status = @playright) then
- self.x := self.x + 3
- else
- self.x := self.x - 3
- )
- method afterInit self {class FlyBy} #rest args ->
- (
- setupPenguins self
- setupSleigh self
- setupTiny self
-
- self
- )
-
-
-
- class HolidayCard (Window)
- inst vars
- background
- flyby
- jingles
- kman
- end
-
- method initCallBacks self {class HolidayCard} ->
- (
- local flyby := self.flyby
- local bg := self.background
- local winClock := self.clock
- local scale := winClock.scale
-
- -- add callback to move flyby across the screen
- addPeriodicCallBack winClock (self -> tick self undefined) flyby #() 1
- -- add callback to move background upward
- addPeriodicCallBack winClock (self -> tick self undefined) bg #() 1
-
- -- add background to window
- addTimeCallBack winClock addBG bg #() 0 false
-
- -- add penguins to window
- addTimeCallBack winClock addPenguins flyby #() 0 false -- 50
-
- -- add sleigh to window
- addTimeCallBack winClock addSleigh flyby #() 0 false -- 150
-
- -- remove penguins from window
- addTimeCallBack winClock removePenguins flyby #() 370 false
-
- -- remove sleigh from window
- addTimeCallBack winClock removeSleigh flyby #() 650 false
-
- -- add tiny to window
- addTimeCallBack winClock addTiny flyby #() 660 false
-
- -- remove tiny from window
- addTimeCallBack winClock removeTiny flyby #() 980 false
-
- -- add kman to window and start scrolling
- addTimeCallBack winClock startScroll bg #() 980 false
-
- -- remove background from window and stop scrolling
- addTimeCallBack winClock stopScroll bg #() 1145 false
- )
-
- method start self {class HolidayCard} ->
- (
- self.clock.rate := 1
- play self.jingles
- )
-
- method reset self {class HolidayCard} ->
- (
- local flyby := self.flyby
- local bg := self.background
- local winClock := self.clock
- local jingles := self.jingles
-
- winClock.rate := 0
- winClock.time := 0
- stop jingles
-
- -- reset jingles
- playPrepare jingles 1
- gotobegin jingles
-
- -- reset background
- bg.position := new Point x:0 y:0
- emptyout bg
-
- -- reset flyby
- playRight flyby
- flyby.position := new Point x:-1300 y:100
- emptyout flyby
- )
-
- method stop self {class HolidayCard} ->
- (
- self.clock.rate := 0
- stop self.jingles
- )
-
- method init self {class HolidayCard} #rest args ->
- (
- apply nextmethod self boundary:(new rect x2:640 y2:480) \
- name:"Happy Holidays 1995" \
- fill:whiteBrush \
- centered:true args
- self.clock.rate := 0
- self.clock.scale := 15
- self
- )
-
- method afterInit self {class HolidayCard} #rest args ->
- (
- -- import colormap
- local theStream := getStream mediaDir "bkground.bmp" @readable
- self.colormap := importMedia theImportExportEngine theStream @image @dib @colormap
-
- -- add background
- self.background := new Background
- prepend self self.background
-
- -- add flyby
- self.flyby := new FlyBy
- prepend self self.flyby
-
- initCallbacks self
-
- -- import jingles
- local theStream := getStream mediaDir "jingles.aif" @readable
- self.jingles := importMedia theImportExportEngine theStream \
- @sound @aiff @player container:self.title
- self
- )
-
- method afterLoading self {class HolidayCard} str ->
- (
- nextmethod self str
- loadDeep self
-
- reset self
- )
-